﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace QLTB_CTK34
{
    public enum KieuDuLieu
    {
        Float,
        String,
        Interger,
        DateTime,
        DateTime_Day,
        DateTime_Month,
        DateTime_Year
    }
    public class DisplayColumnName
    {
        public DisplayColumnName(string table_name, string column_name, string displaycolumn_name,KieuDuLieu kdl)
        {
            TableName = table_name;
            ColumnName = column_name;
            DisPlayColumnName = displaycolumn_name;
            KDL = kdl;
        }
        public string ColumnName, DisPlayColumnName, TableName;
        public KieuDuLieu KDL = KieuDuLieu.String;
        public bool Compare(object txtValue, object ValueCompare, string KieuSoSanh)
        {
            bool kq = false;
            int ss=-1;
            try
            {
                if (txtValue.ToString() != "")
                {
                    switch (KDL)
                    {
                        case KieuDuLieu.Float:
                            ss = -float.Parse(txtValue.ToString()).CompareTo(float.Parse(ValueCompare.ToString()));
                            if (KieuSoSanh == ">")
                                kq = ss > 0;
                            if (KieuSoSanh == ">=")
                                kq = ss >= 0;
                            if (KieuSoSanh == "<")
                                kq = ss< 0;
                            if (KieuSoSanh == "<=")
                                kq = ss<= 0;
                            if (KieuSoSanh == "=")
                                kq = ss == 0;

                            break;
                        case KieuDuLieu.String:
                           ss=-txtValue.ToString().Trim().ToLower().CompareTo(ValueCompare.ToString().Trim().ToLower());
                            if (KieuSoSanh == ">")
                                kq = ss> 0;
                            if (KieuSoSanh == ">=")
                                kq = ss>= 0;
                            if (KieuSoSanh == "<")
                                kq = ss < 0;
                            if (KieuSoSanh == "<=")
                                kq = ss <= 0;
                            if (KieuSoSanh == "=")
                                kq = ss== 0;
                            if (KieuSoSanh == "Like")
                                kq = Regex.IsMatch(ValueCompare.ToString().Trim().ToLower(), @txtValue.ToString().Trim().ToLower());

                            break;
                        case KieuDuLieu.Interger:
                            ss = -int.Parse(txtValue.ToString()).CompareTo(int.Parse(ValueCompare.ToString()));
                            if (KieuSoSanh == ">")
                                kq =ss > 0;
                            if (KieuSoSanh == ">=")
                                kq = ss >= 0;
                            if (KieuSoSanh == "<")
                                kq =ss < 0;
                            if (KieuSoSanh == "<=")
                                kq =ss <= 0;
                            if (KieuSoSanh == "=")
                                kq = ss== 0;

                            break;
                        case KieuDuLieu.DateTime:
                            ss = -DateTime.Parse(txtValue.ToString()).CompareTo(DateTime.Parse(ValueCompare.ToString()));
                            if (KieuSoSanh == ">")
                                kq = ss > 0;
                            if (KieuSoSanh == ">=")
                                kq = ss>= 0;
                            if (KieuSoSanh == "<")
                                kq = ss < 0;
                            if (KieuSoSanh == "<=")
                                kq =ss <= 0;
                            if (KieuSoSanh == "=")
                                kq = ss == 0;
                            break;
                        case KieuDuLieu.DateTime_Day:
                            ss = -int.Parse(txtValue.ToString()).CompareTo(DateTime.Parse(ValueCompare.ToString()).Day);
                            if (KieuSoSanh == ">")
                                kq =ss > 0;
                            if (KieuSoSanh == ">=")
                                kq = ss >= 0;
                            if (KieuSoSanh == "<")
                                kq =ss < 0;
                            if (KieuSoSanh == "<=")
                                kq = ss <= 0;
                            if (KieuSoSanh == "=")
                                kq = ss == 0;
                            break;
                        case KieuDuLieu.DateTime_Month:
                            ss =-int.Parse(txtValue.ToString()).CompareTo(DateTime.Parse(ValueCompare.ToString()).Month);
                            if (KieuSoSanh == ">")
                                kq = ss > 0;
                            if (KieuSoSanh == ">=")
                                kq = ss >= 0;
                            if (KieuSoSanh == "<")
                                kq = ss < 0;
                            if (KieuSoSanh == "<=")
                                kq = ss <= 0;
                            if (KieuSoSanh == "=")
                                kq = ss == 0;
                            break;
                        case KieuDuLieu.DateTime_Year:
                            ss = -int.Parse(txtValue.ToString()).CompareTo(DateTime.Parse(ValueCompare.ToString()).Year);
                            if (KieuSoSanh == ">")
                                kq = ss > 0;
                            if (KieuSoSanh == ">=")
                                kq = ss >= 0;
                            if (KieuSoSanh == "<")
                                kq = ss < 0;
                            if (KieuSoSanh == "<=")
                                kq = ss <= 0;
                            if (KieuSoSanh == "=")
                                kq = ss == 0;
                            break;
                        default:
                            break;
                    }
                }
                else
                {
                    kq = true;
                }
            }
            catch(Exception ex)
            {
            }
            return kq;
        }
    }
}
